package com.kou.backend.api.file;

import com.kou.backend.request.file.UploadFileRequestDTO;
import com.kou.backend.resposne.ResultResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author: kou
 * @since: 2025/6/25 18:08
 */
@Tag(name = "文件操作（上传）相关接口")
@RequestMapping("v1/api/file-ops")
@Validated
public interface FileOpsClient {
    /**
     * 上传文件
     *
     * @param
     * @return result
     */
    @PostMapping(path = "/upload-file")
    ResultResponse storeFile(MultipartFile file, UploadFileRequestDTO uploadFileRequestDTO) throws IOException;

    /**
     * 检查文件是否已存在（用于秒传）
     */
    @PostMapping("/check-file")
    ResultResponse<Boolean> checkFileExists(String fileMd5);

    /**
     * 获取已上传的分片列表（用于断点续传）
     */
    @PostMapping("/uploaded-chunks")
    ResultResponse<List<Integer>> getUploadedChunks(String fileMd5);

    /**
     * 上传单个分片
     */
    @PostMapping(path = "/upload-chunk")
    ResultResponse uploadChunk(String fileMd5, Integer chunkNumber, MultipartFile file) throws IOException;

    /**
     * 合并所有分片
     */
    @PostMapping("/merge-chunks")
    ResultResponse<String> mergeChunks(String fileMd5, String originalFileName) throws IOException;

    /**
     * 下载文件
     */
    @GetMapping("/download-file")
    void downloadFile(String fileId, HttpServletResponse response) throws IOException;

    /**
     * 删除文件
     */
    @PostMapping("/delete-file")
    ResultResponse deleteFile(String fileId) throws IOException;
}
